<template>
	<view>
		<view class="center">
			<view class="tab">
				<view class="tabBars" v-for="(item,index) in tabBars" @click="tabChange(index)"
					:style="tabStyle(index)">
					{{item}}
					<view class="tabBottom" :style="tabBottomStyle(index)"> </view>
				</view>
			</view>
			<!-- -->
			<view class="list" v-for="(item,index) in list" @click.stop-="toDetaile(item)" :key="index">
				<biaofun-datetime-picker v-if="(!item.departTime || !item.scheduleTime) && item.status==3"
					:isFree="true" placeholder="1111111111111111" start="2000-02-03 00:00" end="2100-10-28 00:00"
					fields="minute" style1="opacity: 0;position:absolute;" @change="changeDatetimePicker">
				</biaofun-datetime-picker>

				<view class="list_top">
					<view class="list_serviceName">
						{{item.serviceName }} <text v-if="!item.scheduleTime">{{' ×' + status3.length}}</text>
					</view>
					<!-- 未完成 -->
					<view class="list_status" :style="statusStyle(item.status,index,item)">
						{{statusShow(item.status,index,item)}}
					</view>
				</view>
				<view class="list_split">

				</view>

				<view class="list_name" v-if="item.scheduleTime">
					<image src="../../../static/icon/order/time.png" alt="">{{changeTime(item.scheduleTime) }}</image>
				</view>
				<view class="list_name">
					<image src="../../../static/icon/order/address.png" alt="" style="height: 36rpx; top: 6rpx;">
					</image>
					<view class="">
						{{item.address}}
					</view>
				</view>
				<view class="list_number">
					订单编号:{{item.number}}
				</view>
				<view class="" v-if="item.collaboratorsMultiplayerInfo && item.collaboratorsMultiplayerInfo.length > 0">
					<view class="list_number" >
						采血码:<block  v-for="(item,index) in item.collaboratorsMultiplayerInfo">{{ `${index+1}、${item.patientName}(${item.bloodCollectionTubeCode})` }}</block>
					</view>
				</view>
				<view class="list_price">
					￥{{item.price}}
				</view>
				<view class="list_bottom">
					<view>
						<image class="button-icon" v-show="showEdit(item)" src="http://loto.oss-cn-shanghai.aliyuncs.com/email/b2d50cd953d841a4.png" @click.stop="btn3(item)"/>
					</view>
					
				<!-- 	<view class="list_detaile one" v-show="!item.departTime"
						>修改
					</view> -->
					<view class="flex">
						<view class="list_detaile one" v-show="btnText(item.status,index,item).btn1"
							@click.stop="btn1(item.status,item)">{{btnText(item.status,index,item).btn1}}
						</view>
						
						
						
						<view class="list_detaile" v-show="btnText(item.status,index,item).btn2"
							@click.stop="btn2(item.status,item)">
							<!-- !item.scheduleTime && item.status==3 -->
							<biaofun-datetime-picker
								v-if="(!item.departTime || !item.scheduleTime) && item.status==3 && uncompleteOrder"
								placeholder="1111111111111111" start="2000-02-03 00:00" end="2100-10-28 00:00"
								fields="minute" style1="opacity: 0;position:absolute;" @change="changeDatetimePicker">
							</biaofun-datetime-picker>
							{{btnText(item.status,index,item).btn2}}
						</view>
					</view>
				</view>

			</view>
			<uni-confirm :show="confirmShow" :title="confirmTitle" :content="confirmContent" @cancel="bindBtn('cancel')"
				@confirm="bindBtn('confirm')">
			</uni-confirm>
			<!-- 无订单 -->
			<view class="none" v-if="list.length<1">
				<image src="../../../static/none/order.png" mode=""></image>
				<view class="noneTitle" style="text-align:center;">暂无订单~</view>
			</view>

			<Model :bol="flag" @handleFlag="handleFlag" :auth="auth"></Model>
		</view>
		<uni-popup ref="popup" type="center" :mask-click="false">
			<!-- <uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="同意" title="通知" content="欢迎使用 uni-popup!" @confirm="dialogConfirm"
		        @close="dialogClose"></uni-popup-dialog> -->

			<view class="uni-popup">
			<!-- 	<view class="img">
					<img src="@/static/img/line-order/consum.png" alt="" srcset="">
				</view> -->
				<view class="title">耗材信息</view>
				<view class="tips">
					<text class="red">温馨提醒：</text>当前订单的耗材，请在第一次上门时，将用户购买的<text
						class="red">全部耗材送至服务地址</text>，耗材费将在首次服务完成后结算至您的账号余额内！
				</view>
				<view class="contents">
					<view class="content">
						<view class="ltitle">{{consumPopup.name}}{{consumPopup.num}}</view>
					</view>
					<view class="desc">{{consumPopup.detail}}</view>
					<view class="content money">
						<view class="ltitle">结算金额</view>
						<view class="right">¥{{consumPopup.price}}</view>
					</view>
				</view>

				<view class="btns" @click="$refs.popup.close()">
					我已知晓
				</view>
			</view>
		</uni-popup>
		<!-- @click="btn" -->
		<uni-popup ref="popupHospital" type="center" style="z-index:99;">
			<view class="sunui">
				<view class="hospitalBox">
					<view class="belong">
						所属医院：
					</view>
					<input class="inpt" type="text" v-model="hospitalAddress1" placeholder="请填写您的所属医院" />
					<button class="subBtn" @click="subBtn">确定</button>
				</view>
			</view>
		</uni-popup>
		<!-- 提示信息弹窗 -->
		<uni-popup ref="message" type="center">
			<view class="box mar df" style="background-color: #fff;padding: 5%;width: 90%;margin-top: -80%;">
				<view class="" style="width: 80rpx;">
					<image :src="premissionPic" mode="" style="width: 45rpx;height: 45rpx"></image>
				</view>
				<view class="">
					<view class="" style="font-weight: bold;font-size: 26rpx;">
						{{premissionValue}}
					</view>
					<view class="">
						{{premissionInfo}}
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="isStartRecord" type="center" :mask-click="false">
			<view class="d-j-center" style="width: 600rpx;">
				<view class="" style="background-color: #fff;padding: 8% 5% 8% 5%;width: 100%;">
					<view class="" style="font-size: 32rpx;">
						您的服务暂未结束，请选择继续录音：
					</view>
					<button class="record-l" @click="confirmRecord" style="margin-top: 5%;width: 60%;">确定</button>
				</view>
			</view>
		</uni-popup>
		<confirm ref="confirmModal" :content="confirmContent2" @onOk="onOk" />
	</view>
</template>

<script>
	import {
		getLocation3,
		getLocation4,
	} from '@/common/js/location.js'
	import record from '@/mixins/record.vue'
	import permision from '@/common/js/permission.js'
	import {
		debounce
	} from '@/common/js/throttle.js'
	import {
		selectNurseInfoCheckById
	} from '@/apis/certificate/certification.js'
	import {
		selectAllUrgencyLinkman
	} from '@/apis/security/index.js'
	import uniConfirm from '@/components/uni-ui/uni-confirm/uni-confirm.vue'
	import uniPopup from '@/components/uni-ui/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-ui/uni-popup-message/uni-popup-message.vue'
	import {
		sonOrderList,
		updateReceiptStatus,
		mobileUser,
		updateServeTime,
		updateDepartTime,
		selectByServerNumber,
		updateOrderStatus,
		selectOrderStatusData,
		nurseAuthorizationLocating,
		nurseWhetherItIsAHundredMeters,
		endOfServiceThreeHundredMeters
	} from '@/apis/order/index.js'
	import {
		selectConfigurationByServiceId
	} from '@/apis/nurse-report/index.js'
	import biaofunDatetimePicker from '@/components/uni-ui/biaofun-datetime-picker/biaofun-datetime-picker.vue'
	import refresh from '@/components/common/refresh/index.vue'
	import uniLoadMore from '@/components/uni-ui/uni-load-more/uni-load-more.vue'
	import confirm from '@/components/common/confirm/index.vue'
	import dayjs from "@/plugin/dayjs/dayjs.min.js";
	export default {
		mixins: [record],
		data() {
			return {
				uncompleteOrder: true,
				premissionValue: '',
				premissionInfo: '',
				premissionPic: '',
				hospitalAddress: '',
				hospitalAddress1: '',
				confirmType: 1,
				curItem: null,
				file: null,
				flag: false,
				auth: 'location',
				text: '', //点击按钮文字
				confirmShow: false,
				// confirmShow: false,
				confirmTitle: '是否确认开始服务?',
				departTimeObj: {},
				confirmContent: '温馨提示：点击“确认”即表示已经上门服务，为了保证您的人身财产安全，平台将全程录音记录，切勿恶意点击！',
				//判断下拉刷新
				// canRefresh: true,
				//时间
				show: false,
				tabBars: ['全部', '已接单', '服务中', '已完成'],
				//判断tab切换样式
				tabNum: 0,
				number: '', //获取子订单列表的 母订单订单号
				subNum: '', //开始服务的子订单订单号
				status: '', // ''所有 3已接单 4服务中 5已完成
				list: [],
				//订单根据status分类
				status3: [],
				length: '', //为填写时间订单的长度
				other: '',
				noReturn: false, //trun 接单后禁止返回订单详情
				consumPopup: '', //耗材弹框
				curObj: null,
				page: {
					nurseId: this.$store.state.userInfo.id,
				},
				confirmContent2: [
					'为了保证您的个人安全以及更好的给您进行派单或抢单：',
					'1.请您授权【护士小鹿-护士端】始终允许使用您的设备地理位置信息；',
					'2.在您退出【护土小鹿-护士端】后，我们将不在获取您的设备位置信息；'
				],
				state: [{
						state: 1,
						value: '已接单',
					},
					{
						state: 2,
						value: '服务中',
					},
					{
						state: 3,
						value: '已完成',
					},
					{
						state: 4,
						value: '已取消',
					},
				],
				isHavePerson: 0,
				isRecord: false,
				isRecordList: [],
				uploadTimeType: '', // 区分上传服务时间还是出发时间

			}
		},
		// 页面滚动,剩余高度是280
		// onPageScroll(e) {
		// 	this.canRefresh=e.scrollTop==0?true:false
		// },
		onLoad(option) {
			console.log('进入了onload-----------');
			if (option.number) {
				this.number = option.number
			}
			if (option.noReturn) {
				this.noReturn = option.noReturn
			} else {
				this.noReturn = false
			}
			// this.$nextTick(() => {
			// 	this.$refs.popup.open()
			// })
			if (option.status && option.status == 3) {
				this.getAlert()
			}
			this.initContact()
		},
		onShow() {
			this.getUncompleteOrder()
			this.getOrder()
			console.log('onshow执行了吗--------------------');
			this.getStatus()
			console.log('onshow执行了吗222222--------------------');
			this.confirmShow = false
			let _this = this
			uni.$on('selectTime', (res) => {
				_this.form.scheduleTime = res.scheduleTime
				_this.time = res.time
				// console.log(res,'时间');
			})
			this.initContact()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.getOrder()
			this.getStatus()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		// 自定义返回事件必须要添加return true 要不然自定义事件不生效!!!
		onBackPress() {
			// console.log(this.noReturn, '点击了返回事件------------');
			if (this.noReturn) {
				uni.switchTab({
					url: '../../tabbars/order/order',
				})
				return true
			} else {
				return false
			}
		},
		components: {
			biaofunDatetimePicker,
			uniLoadMore,
			refresh,
			uniConfirm,
			uniPopup,
			uniPopupMessage,
			confirm
		},
		computed: {
			showEdit(item) {
				// 省市区 且 有预计出发时间 且 未填写 预计到达时间 && 且未修改过
				return function(item) {
					// return true
					return item.economize && item.addressCity && item.distinguish && item.scheduleTime && !item.departTime && !item.isAddressModified
				}
			},
			changeTime(time) {
				return function(time) {
					let time1 = dayjs(time).day()
					console.log("时间", time1)
					let map = {
						0: '周日',
						1: '周一',
						2: '周二',
						3: '周三',
						4: '周四',
						5: '周五',
						6: '周六',
					}
					return dayjs(time).format('YYYY[年]MM[月]DD[日] ') + map[time1] + dayjs(time).format(' AHH:mm:ss')
				}
			},
			tabStyle(index) {
				let num = this.tabNum
				return function(index) {
					if (num == index) {
						return `font-weight: 500;color: #333333;`
					} else {
						return false
					}
				}
			},
			tabBottomStyle(index) {
				let num = this.tabNum
				return function(index) {
					if (num == index) {
						return `display:block;`
					} else {
						return false
					}
				}
			},
			//点击按钮文本
			btnText(status, index, item) {
				return function(status, index, item) {
					if (status == 3) {
						if (!item.scheduleTime) {
							return {
								btn1: '拨打电话',
								btn2: '填写时间',
							} //'待填写'
						} else if (!item.departTime) {
							return {
								// 开始服务前填写报告的条件：status==3 and item.scheduleTime
								btn1: '拨打电话',
								btn2: '确认出发',
							} //'已接单 但还未填写出发时间'
						} else {
							return {
								// 开始服务前填写报告的条件：status==3 and item.scheduleTime
								btn1: '拨打电话',
								btn2: '开始服务',
							} //'已接单'
						}
					} else if (status == 4) {
						// console.log('这是4')
						if (item.nursingRecordStatus == 1) {
							return {
								btn1: '联系机构',
								btn2: '查看报告',
							} //'待审核'
						} else if (
							!item.nursingRecordStatus ||
							item.nursingRecordStatus == 3
						) {
							return {
								btn1: '联系机构',
								btn2: item.showStatus == 0 ? '服务结束' : '填写报告',
							} //'服务中'
						}
					} else if (status == 5) {
						return {
							btn1: '',
							btn2: '查看报告',
						} //'已完成'
					} else if (status == 6) {
						return {
							btn1: '',
							btn2: '',
						} //'取消'
					} else if (status == 7) {
						return {
							btn1: '',
							btn2: '联系机构',
						} //'已退款'
					} else if (status == 8) {
						return {
							btn1: '',
							btn2: '联系机构',
						} //'异常'
					} else if (status == 9) {
						return {
							btn1: '',
							btn2: '联系机构',
						} //'退款中'
					} else if (status == 10) {
						return {
							btn1: '',
							btn2: '',
						} //‘已拒绝
					} else {
						return {
							btn1: '',
							btn2: '',
						} //‘已拒绝
					}
				}
			},
		},
		beforeDestroy() {
			uni.$off('selectTime')
		},
		methods: {
			confirmRecord() {
				try {
					this.startRecord()
					// this.getOrder()
					this.getStatus()
					console.log('录音权限')
					this.isRecord = this.$store.state.isRecord
					console.log('触发222222222222222222====', this.isRecord)
				} catch (e) {
					console.log("333333333===", e)
					//TODO handle the exception
				}
				this.$refs.isStartRecord.close()
			},
			getRecordStatus() {
				this.getStatus()
				this.isRecord = this.$store.state.isRecord
				let webView = this.$scope.$getAppWebview();
				// 服务结束的按钮，代表服务中，已经开始录音 
				console.log('getRecordStatus-----------', this.isRecord, this.isRecordList, );
				if (this.isRecordList[0].status == 4 && this.isRecordList[0].showStatus == 0) {
					if (this.isRecord == false) {
						console.log('重新开始录音');
						this.$refs.isStartRecord.open()
						webView.setStyle({
							titleNView: {
								autoBackButton: false
							}
						})
					} else if (this.isRecord == true) {
						console.log('正常不需要操作');
						webView.setStyle({
							titleNView: {
								autoBackButton: true
							}
						})
					}
				}
			},
			async subBtn() {
				console.log(this.hospitalAddress1)
				if (this.hospitalAddress1 == '') {
					//给提示
					uni.showToast({
						icon: 'none',
						title: '请填写您的所属医院',
					})
				} else {
					this.hospitalAddress = this.hospitalAddress1
					this.$store.commit('setHospitalAddress', this.hospitalAddress)
					this.$refs.popupHospital.close()
				}
			},
			getAlert() {
				selectByServerNumber({
					number: this.number,
				}).then((r) => {
					// console.log(r, 'rrrrrr')
					if (r.success && r.object) {
						let object = r.object
						this.consumPopup = {
							price: object.price || 0,
							name: object.consumableBagOrder.name || '',
							num: '*' + object.consumableBagOrder.num || 1,
							detail: object.consumables[0].bleName || '',
						}
						this.$refs.popup.open()
					}
				})
			},
			tabChange(index) {
				console.log("想看的数据", this.tabNum == index)
				if (this.tabNum == index) return
				this.tabNum = index
				if (index == 0) {
					this.status = ''
				} else if (index == 1) {
					this.status = 3
				} else if (index == 2) {
					this.status = 4
				} else if (index == 3) {
					this.status = 5
				}
				this.getOrder()
			},
			//按钮1操作
			async btn1(status, item) {
				console.log(item)
				let res = await this.handleJudgeCall()
				if (!res) {
					return
				}
				if (status == 3) {
					this.call(item.number, item.userId)
				} else if (status == 4) {
					this.callLoto()
				}
				this.timeShow = true
			},

			//按钮2操作
			async btn2(status, item) {
				console.log(status, item)
				if (status == 3) {
					if (!item.scheduleTime && this.uncompleteOrder) {
						this.uploadTimeType = "serviceTime"
						plus.nativeUI.toast('请选择服务时间～')
					} else if (!item.departTime) {

						this.hasDepartureTime(item)
					} else {
						this.curObj = item
						this.curItem = item.number
						// 获取经纬度
						getLocation4().then(res => {
							let data = {
								...res,
								orderNumber: this.curItem,
							}
							// 判断是否能够打卡
							nurseWhetherItIsAHundredMeters(data).then(res1 => {
								if (res1.success) {
									// return
									this.beforeStart(item)
								}


							}).catch(err => {
								// #ifdef APP
								plus.nativeUI.toast(err.object)
								// #endif
							})
						})
					}
				} else if (status == 4) {
					// 4为查看或者填写护理报告
					if (item.nursingRecordStatus == 1) {
						// 查看护理报告
						this.seeReport(item)
					} else if (
						!item.nursingRecordStatus ||
						item.nursingRecordStatus == 3
					) {
						// 有护理报告的状态或者护理报告状态为3的情况下填写护理报告
						this.curObj = item
						this.curItem = item.number
						this.write(item.number, item)
					}
				} else if (status == 5) {
					this.seeReport(item)
				} else if (status == 7) {
					this.callLoto()
				} else if (status == 8) {
					this.callLoto()
				} else if (status == 9) {
					this.callLoto()
				}
			},
			btn3(item) {
				let data = {
					scheduleTime: item.scheduleTime,
					number: item.number,
					economize: item.economize,
					addressCity: item.addressCity,
					distinguish: item.distinguish,
					addressDetails: item.addressDetails,
				}
				uni.navigateTo({
					url:'/pages/order/edit-order/index?data=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			//查看护理报告
			seeReport(item) {
				console.log("报告！！！！！！！", this.$store.state.userInfo.identity)
				if (this.$store.state.userInfo.identity == 3) {
					// #ifdef APP
					plus.nativeUI.toast('暂无报告可查看!')
					// #endif
					return
				}
				uni.navigateTo({
					url: '../../report/report-detaile/report-detaile?id=' +
						item.nursingRecordId,
				})
			},
			//查看订单详情
			toDetaile(item) {
				if (item.status == 3 && !item.scheduleTime) {
					this.uploadTimeType = "serviceTime"
					plus.nativeUI.toast('请选择服务时间～')
				} else if (!item.departTime && item.status == 3) {
					this.hasDepartureTime(item)
				} else {
					uni.navigateTo({
						url: '../order-detaile/order-detaile?number=' + item.number,
					})
				}
			},
			async initContact() {
				let res = await selectAllUrgencyLinkman()
				if (res.success) {
					if (res.object.length > 0) {
						this.isHavePerson = 1
					}
				}
			},

			handleFlag(value) {
				this.flag = !!value
			},
			// 是否存在正在进行的订单
			async getUncompleteOrder() {
				// 新接口专门判断有无进行中的订单
				let res = await selectOrderStatusData(this.page)
				console.log("进行中的订单========", res)
				if (res.success) {
					let flag = res.object
					this.uncompleteOrder = flag
					this.$store.commit('getUncompleteOrder', flag)
				}
			},
			hasDepartureTime(item) {
				if (!this.$store.state.hasUncompleteOrder) {
					// #ifdef APP
					plus.nativeUI.toast('您有未完成订单，请填写护理报告完成订单!')
					// #endif
					return
				}
				console.log("订单数据", item)
				this.uploadTimeType = "departureTime"
				this.curObj = item
				this.curItem = item.number
				// this.beforeStart(item)
				plus.nativeUI.toast('请选择预计到达时间～')
			},
			async beforeStart(item) {
				// 1、是否有预计到达时间
				// 2、未完成订单 是否有医院
				// 3、是否存在紧急联系人
				// 4、是否录音
				// 5、是否定位
				// 6、判断是否签名



				// var pages = getCurrentPages();
				// var currPage = pages[pages.length - 1]; //当前页面
				// console.log(currPage, '---------------')


				// 紧急联系人
				// console.log('结果最后1次判断', this.isHavePerson, this.isHavePerson == 0);
				if (this.isHavePerson == 0) {
					this.confirmShow = true
					this.confirmContent = ''
					this.confirmTitle = '请添加紧急联系人！'
					this.confirmType = 8
					return
				} else {
					this.confirmTitle = '是否确认开始服务?'
					this.confirmContent =
						'温馨提示：点击“确认”即表示已经上门服务，为了保证您的人身财产安全，平台将全程录音记录，切勿恶意点击！'
					this.confirmType = 1
				}

				// #ifdef APP-PLUS



				// 填写医院地址
				let id = this.$store.state.userInfo.id
				// console.log('id', id)
				let res = await selectNurseInfoCheckById({
					id,
				})
				// console.log(res)
				// console.log(this.$store.state.userInfo.identity)
				this.hospitalAddress = res.object.hospitalAddress
				this.$store.commit('setHospitalAddress', this.hospitalAddress)
				if (
					this.hospitalAddress1 == '' &&
					this.$store.state.userInfo.identity == 1
				) {
					if (
						res.object.hospitalAddress == '' ||
						res.object.hospitalAddress == null
					) {
						this.$refs.popupHospital.open()
						return
					}
				} else {
					// console.log(1)
				}

				// 定位权限
				// 没请求过权限，则需请求
				// 请求过权限，如果被拒绝，则文字提示

				// 录音授权
				let result = -1
				if (uni.getSystemInfoSync().platform === 'android') {
					result = await permision.requestAndroidPermission(
						'android.permission.RECORD_AUDIO'
					)
				} else {
					result = await permision.judgeIosPermission('record')
				}
				if (result != 1) {
					if (uni.getSystemInfoSync().platform == 'android') {
						// #ifdef APP
						plus.nativeUI.toast('请开启录音权限！')
						// #endif
						return
					} else {
						this.auth = 'luyin'
						this.handleFlag(true)
						return
					}
				}

				// 定位授权
				let loc = -1
				if (uni.getSystemInfoSync().platform == 'android') {
					loc = await permision.requestAndroidPermission(
						'android.permission.ACCESS_FINE_LOCATION'
					)
				} else {
					loc = await permision.judgeIosPermission('location')
				}

				if (loc != 1) {
					if (uni.getSystemInfoSync().platform == 'android') {
						// #ifdef APP
						plus.nativeUI.toast('请开启定位权限！')
						// #endif
						return
					} else {
						this.auth = 'location'
						this.handleFlag(true)
						return
					}
				} else {

				}


				// #endif

				// 是否签名
				if (this.curObj.disclaimer) {
					if (this.curObj.isSign == -1) {
						this.getAssure(item)
						return
					}
				}


				this.toInfo(item)
			},
			toInfo: debounce(
				function(item) {
					if (
						item.nursingRecordId == null && [1].includes(this.$store.state.userInfo.identity)
					) {
						// 填写报告
						selectConfigurationByServiceId({
							serviceId: item.serviceId,
						}).then((r) => {
							uni.setStorageSync(
								'reportTemplate',
								JSON.stringify(r.object)
							)
							uni.navigateTo({
								url: '../../report/fill-in-report/report?number=' +
									item.number,
							})
						})
					} else {
						console.log('在当前订单详情页面继续进行操作')
						this.start()
					}
				},
				1000,
				true
			),
			toInfol: debounce(
				function(item) {
					selectConfigurationByServiceId({
						serviceId: item.serviceId,
					}).then((r) => {
						uni.setStorageSync(
							'reportTemplate',
							JSON.stringify(r.object)
						)
						uni.navigateTo({
							url: '../../report/fill-in-report/report?number=' +
								item.number,
						})
					})
				},
				1000,
				true
			),
			//开始服务
			async start() {
				this.subNum = this.curItem
				this.confirmShow = true
			},
			getAssure(item) {
				uni.navigateTo({
					url: `../assure?number=${this.curItem}&img=${this.curObj.disclaimer}&serviceId=${item.serviceId}`
				})
			},
			//confirm 确定取消
			async bindBtn(type) {
				// console.log('确定取消弹窗item', item)
				// console.log('确定或者取消', type)
				let number = this.subNum
				if (type == 'confirm') {
					if (this.confirmType == 8) {
						uni.navigateTo({
							url: '../../../pages/emergency-contact/list/list',
						})
						return
					}

					// 为了保证您的人身财产安全，平台将全程录音记录，
					let hospitalAddress = this.hospitalAddress
					let res = await updateReceiptStatus({
						hospitalAddress,
						number,
						// ...this.$store.state.startServeLocation,
					})
					if (res.success) {
						this.$store.commit('setcurItem', this.subNum)
						try {
							this.startRecord()
							this.getStatus()
							this.isRecord = this.$store.state.isRecord
							let webView = this.$scope.$getAppWebview();
							webView.setStyle({
								titleNView: {
									autoBackButton: true
								}
							})
						} catch (e) {
							//TODO handle the exception
						}
						// #ifdef APP
						plus.nativeUI.toast('您已开始服务~')
						// #endif
						setTimeout(() => {
							this.confirmShow = false
							// 原来线上
							uni.navigateTo({
								url: '../order-detaile/order-detaile?number=' +
									number,
							})
						}, 500)
					}
				} else {
					this.confirmShow = false
					console.log('需要停留在当前sub-order页面')
				}
				// }
			},
			//拨打电话
			async call(number, userId) {
				let data = {
					number: number,
					userId: userId,
					uuid: this.$store.state.uuid,
				}
				let res = await mobileUser(data)
				if (res.success) {
					console.log(res, '拨打电话')
					uni.makePhoneCall({
						phoneNumber: res.object,
					})
				}
			},
			//填写护理报告
			write(number, item) {
				console.log('item1111111', item)
				// 状态为4且按钮为服务结束  然后更新订单状态
				if (item.status == 4 && item.showStatus == 0) {
					console.log("触发服务结束")

					this.$store.commit('setcurItem', number)
					getLocation4().then(res => {
						let data = {
							...res,
							orderNumber: number,
						}
						// 判断是否能够打卡
						endOfServiceThreeHundredMeters(data).then(res1 => {
							if (res1.success) {
								// return
								console.log("订单状态进入上传录音", res1)
								this.stopRecord(this.updateOrderStatus)
							}


						}).catch(err => {
							// #ifdef APP
							plus.nativeUI.toast(err.object)
							// #endif
						})
					})

				} else if (item.status == 4 && item.showStatus == 1) {
					this.toInfol(item)
					this.getOrder()
				}
				// 原来线上
				// uni.navigateTo({
				// 	url: '../../report/fill-in-report/fill-in-report?number=' + item.number
				// })
				// console.log('serviceId1111111111111', item.serviceId)
			},
			updateOrderStatus() {
				console.log("订单状态进入111111")
				updateOrderStatus({
					number: this.curItem,
				}).then(r => {
					console.log("订单状态进入22222", r)
					if (!r.success) {
						return
					}
					this.getOrder()
					
				}).catch(err=>{
					console.log("时长不够60s")
					this.startRecord()
					this.getStatus()
				})
			},
			async handleJudgeCall() {
				if (uni.getSystemInfoSync().platform === 'android') {
					let result = await permision.requestAndroidPermission(
						'android.permission.CALL_PHONE'
					) //1以获取 0未获取 -1权限禁止
					if (result != 1) {
						this.auth = 'call'
						this.handleFlag(true)
						return false
					}
				}
				return true
			},
			//联系机构
			callLoto() {
				this.$store.dispatch('call')
			},
			todo() {},
			//获取子订单列表list item
			async getOrder() {
				let res = await sonOrderList({
					number: this.number,
					status: this.status,
				})
				console.log('订单数据', res)
				if (res.success) {
					this.isRecordList = res.object.filter((r, index) => {
						return r.status == 4 && r.showStatus == 0
					})
					// console.log('this.isRecordList------------', this.isRecordList);
					this.list = res.object.filter((el) => el.scheduleTime)
					// console.log('list8888888888888', this.list)
					this.status3 = res.object.filter(
						(el) => el.status == 3 && !el.scheduleTime
					)
					if (this.status3.length > 0) {
						this.list.unshift(this.status3[0])
					}
					this.getRecordStatus()
				} else {
					plus.nativeUI.toast('获取订单失败~')
					// uni.showToast({
					// 	icon:'none',
					// 	title:'获取订单失败！'
					// })
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
						})
					}, 500)
				}
				let flag = this.list.filter((l) => {})
				// console.log(this.list, '子订单列表')
			},
			async onOk() {

				// console.log("测试222222222",status)
				// if(status) {
				// 	console.log("测试111111",status)
				// 	// this.$store.dispatch('continuousReportLocation')
				// }
				// console.log("状态",status)

				updateDepartTime(this.departTimeObj).then(res => {
					plus.nativeUI.toast('您已填写预计到达时间~')
					this.getUncompleteOrder()
					getLocation4().then(res => {
						this.$store.dispatch('continuousReportLocation', {
							orderNumber: this.departTimeObj.number
						})
					})
					setTimeout(() => {
						this.getOrder()

					}, 500)
				})
			},
			//填写服务时间
			changeDatetimePicker(time) {
				console.log(88888888888, time)
				if (this.uploadTimeType == "serviceTime") {
					let data = {
						data: time.f3 + ':00',
						number: this.list[0].number,
					}


					console.log(data, '000000000000000000')
					this.timing(data)
				} else {
					let data = {
						date: time.f3 + ':00',
						number: this.curItem,
					}
					this.departTimeObj = data
					console.log("在这==============", data)
					this.$refs.confirmModal.show()
					return

				}

			},
			//上传时间
			async timing(data) {
				let status = this.list.filter((el) => el.status == 4)
				let res = await updateServeTime(data)
				console.log(res, '选择时间')
				if (res) {
					this.timeShow = false
					// #ifdef APP-PLUS
					plus.nativeUI.toast('您已填写服务时间~')
					// #endif
					// #ifdef H5
					uni.showToast({
						icon: 'success',
						title: '您已填写时间！',
					})
					// #endif
					this.getUncompleteOrder()
					setTimeout(() => {
						this.getOrder()
					}, 500)
				}
			},
			//状态
			statusShow(status, index, item) {
				if (status == 3) {
					if (!item.scheduleTime) {
						return '待填写'
					} else {
						return '已接单'
					}
				} else if (status == 4) {
					if (item.nursingRecordStatus == 1) {
						return '待审核'
					} else if (
						!item.nursingRecordStatus ||
						item.nursingRecordStatus == 3
					) {
						return '服务中'
					}
				} else if (status == 5) {
					return '已完成'
				} else if (status == 6) {
					return '已取消'
				} else if (status == 7) {
					return '已退款'
				} else if (status == 8) {
					return '异常'
				} else if (status == 9) {
					return '退款中'
				} else if (status == 10) {
					return '已拒绝'
				}
			},
			//状态样式
			statusStyle(status, index, item) {
				if (status == 3) {
					return `color:#FF6A00;`
				} else if (status == 4) {
					return `color:#FF6A00;`
				} else if (status == 5) {
					return `color:#333333`
				} else if (status == 6) {
					return `color:#999999`
				} else if (status == 7) {
					return `color:#333333`
				} else if (status == 8) {
					return `color:rgba(255, 79, 79, 1)`
				} else if (status == 9) {
					return `color:color:rgba(255, 79, 79, 1)`
				} else if (status == 10) {
					return `color:rgba(153, 153, 153, 1);`
				}
			},
			//下拉加载
			refresh(done) {
				this.getOrder()

				// 不加个延迟好像太快了有点
				setTimeout(() => {
					done()
				}, 500)
			},
		},
	}
</script>

<style lang="scss" scoped>
	.center {
		// height: 100vh;
		min-height: 100vh;
		background: rgba(243, 246, 246, 1);
		width: 100%;
	}

	.tab {
		width: 100%;
		height: 88rpx;
		display: flex;
		background-color: #ffffff;
		padding: 0 58rpx;
		box-sizing: border-box;
		justify-content: space-between;

		.tabBars {
			height: 88rpx;
			line-height: 88rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: rgba(0, 0, 0, 0.38);
			position: relative;

			.tabBottom {
				width: 100%;
				height: 6rpx;
				background-color: #3c8eff;
				border-radius: 9rpx;
				display: none;
				position: absolute;
				bottom: 0rpx;
				left: 0rpx;
				transition: all 10s ease-in-out;
			}
		}
	}

	.list {
		margin: 0 auto;
		width: 710rpx;
		background: #ffffff;
		padding: 28rpx 20rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		// display: flex;
		// justify-content: space-between;
		margin-top: 16rpx;
		position: relative;

		.list_top {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.list_serviceName {
				font-size: 32rpx;
				color: #333333;
			}

			.list_status {
				font-size: 28rpx;
				color: #333333;
			}
		}

		.list_split {
			width: 634rpx;
			height: 2rpx;
			background: rgba(240, 240, 240, 0.6);
			margin: 28rpx auto;
		}

		.list_name {
			margin-bottom: 16rpx;
			font-size: 28rpx;
			position: relative;
			box-sizing: border-box;

			image {
				float: left;
				width: 32rpx;
				height: 32rpx;
				margin-right: 16rpx;
				display: block;
				top: 8rpx;
			}
		}

		.list_number {
			padding-left: 52rpx;
		}

		.list_price {
			font-size: 36rpx;
			color: #ff4f4f;
			line-height: 50rpx;
			text-align: right;
			margin-bottom: 16rpx;
		}

		.list_bottom {
			display: flex;
			justify-content: space-between;
			.button-icon {
				width: 60rpx;
				height: 60rpx;
			}
			.list_detaile {
				position: relative;
				width: 160rpx;
				height: 72rpx;
				background: #3c8eff;
				color: #ffffff;
				text-align: center;
				font-size: 28rpx;
				border-radius: 8rpx;
				line-height: 72rpx;
				margin-left: 24rpx;
			}

			.one {
				background: #ffffff;
				border: 2rpx solid #3c8eff;
				color: #3c8eff;
			}
		}
	}

	.list {
		width: 100%;
		background: #ffffff;
		padding: 26rpx;
		box-sizing: border-box;
		font-family: PingFangSC-Regular, PingFang SC;
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.6);
		margin-bottom: 8rpx;

		.top {
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;

			.left {
				.title {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #333333;
					height: 40rpx;
					line-height: 50rpx;
				}

				.time {
					// height: 50rpx;
					// line-height: 50rpx;
				}
			}

			.right {
				.price {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #3c8eff;
				}

				.state {
					height: 34rpx;
					text-align: right;
				}
			}
		}

		.address {
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 28rpx;
			width: 506rpx;
			// margin-bottom: 20rpx;
		}

		.bottom {
			display: flex;
			justify-content: flex-end;
		}
	}

	.none {
		text-align: center;
		padding-top: 180rpx;

		image {
			width: 442rpx;
			height: 354rpx;
			display: block;
			margin: 0 auto;
			margin-bottom: 80rpx;
		}

		.noneTitle {
			font-size: 36rpx;
			font-weight: 500;
			color: #3e3e3e;
			text-align: center;
		}
	}

	.uni-popup {
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 500rpx;
		padding: 20rpx 48rpx;
		background-color: #fff;
		border-radius: 20rpx;
		font-size: 24rpx;

		.img {
			position: absolute;
			top: -160rpx;
			width: 332rpx;
			height: 232rpx;

			img {
				
				height: 100%;
				width: 100%;
			}
		}

		.title {
			margin: 32rpx 0 32rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #333333;
		}

		.contents {
			margin: 32rpx 0;
			width: 100%;
			padding: 24rpx 26rpx 26rpx 16rpx;
			background: #e0e9f7;
			border-radius: 20rpx;

			.content {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.ltitle {
					position: relative;
					left: 16rpx;

					&::before {
						position: absolute;
						content: '';
						display: inline-block;
						top: 5rpx;
						left: -10rpx;
						width: 8rpx;
						height: 26rpx;
						background: #3c8eff;
						border-radius: 5rpx;
					}
				}

				&.money {
					margin: 24rpx 0;

					.right {
						font-size: 28rpx;
						font-weight: 500;
						color: #ea2027;
					}
				}
			}
		}

		.desc {
			margin: 16rpx 10rpx;
			width: 100%;
			color: #666;
		}

		.tips {
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;

			.red {
				color: #ea2027;
			}
		}

		.btns {
			padding: 12rpx 80rpx;
			background: rgba(60, 142, 255, 1);
			border-radius: 36rpx;
			font-size: 36rpx;
			color: #ffffff;
		}
	}

	.sunui {
		border-radius: 5rpx;
		position: relative;
		width: 650rpx;
		height: 300rpx;
		background-color: #ffffff;
		margin: 0 auto;
		padding: 15rpx 15rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		.hospitalBox {
			width: 100%;

			.belong {
				font-size: 32rpx;
			}

			.inpt {
				margin-top: 12rpx;
				background-color: #fff;
				width: 100%;
				height: 60rpx;
				border-radius: 5rpx;
				// margin-left: 30rpx;
				color: #333;
				border: #93a1a1 2rpx solid;
			}

			.subBtn {
				display: flex;
				justify-content: center;
				border-radius: 5rpx;
				width: 150rpx;
				height: 65rpx;
				background-color: #528df5;
				color: #fff;
				align-items: center;
				line-height: 55rpx;
				margin: 25rpx auto;
			}
		}
	}

	.record-l {
		background: #3c8eff;
		color: #ffffff;
		text-align: center;
		font-size: 28rpx;
		border-radius: 8rpx;
	}
</style>